package ui;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import aboa.club.Employee;
import aboa.club.IMembership;
import aboa.club.Member;
import aboa.club.Membership;

import jxl.Cell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class readExcel {
	
	public ArrayList<Employee> importedEmployess= new ArrayList<Employee>();
	public ArrayList<Member> importedMembers= new ArrayList<Member>();
	
	
	private String inputFile;
	
	public void setInputFile(String inputFile)
	{
		this.inputFile=inputFile;
	}
	
	public void read() throws IOException {
		File inputWorkbook = new File(inputFile);
		Workbook w;
		
		try {
			w = Workbook.getWorkbook(inputWorkbook);
			
			Sheet sheet = w.getSheet(0);
			
			int firstDataRow=1;
			for(int x = firstDataRow;x<sheet.getRows();x++)
			{
				NumberCell nc = (NumberCell) sheet.getCell(4, x);
				
	
			importedEmployess.add( new Employee(sheet.getCell(0, x).getContents()
					,sheet.getCell(1, x).getContents()
					, sheet.getCell(2, x).getContents()
					, sheet.getCell(3, x).getContents()
					,nc.getValue()
					,sheet.getCell(5, x).getContents())) ;
			}
			
			
		//IMporter medlemmer
			sheet = w.getSheet(1);
			
			firstDataRow=1;
			for(int x = firstDataRow;x<sheet.getRows();x++)
			{
				Membership mc = new Membership("Bronze", .9, 10);
			
				if (sheet.getCell(2, x).getContents().equals("Bronze"))
				{				
					mc = new Membership("Bronze", .9, 10);
				}
				else if(sheet.getCell(2, x).getContents().equals("Silver"))
				{
					mc = new Membership("Silver", .75, 20);
				}
				else if(sheet.getCell(2, x).getContents().equals("Gold"))
				{
					mc = new Membership("Gold", .0, 100);
				}
			
						
	
			importedMembers.add( new Member(
					mc
					, sheet.getCell(1, x).getContents()
					, sheet.getCell(3, x).getContents()
					, sheet.getCell(4, x).getContents()
					, sheet.getCell(5, x).getContents()
					, sheet.getCell(0, x).getContents()));
					
					
					
			}

			
			
			
		}catch (BiffException e)
		{
			e.printStackTrace();
		}
	}

}
